package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDto;
import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/category/of/parent")
    public ResponseEntity<List<Category>> findCategoryByPid(@RequestParam("pid") Long pid){
        List<Category> categoryList = categoryService.findCategoryByPid(pid);
        return ResponseEntity.status(HttpStatus.OK).body(categoryList);
    }

    /**
     * 根据分类id集合查询分类对象集合
     */
    @GetMapping("/category/list")
    public ResponseEntity<List<Category>> findCategoriesByIds(@RequestParam("ids") List<Long> ids){
        List<Category> categories = categoryService.findCategoriesByIds(ids);
        return ResponseEntity.ok(categories);
    }
    /**
     * 查询所有分类首页渲染
     * @return
     */
    @GetMapping("/category/subclass")
    public ResponseEntity<List<CategoryDto>>findCategorySubclass(@RequestParam("pid") Long id){

        List<CategoryDto> categoryDtos=categoryService.findCategorySubclass(id);
        return ResponseEntity.ok(categoryDtos);
    }

}
